// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.erosion.obj;

import java.util.ArrayList;
import zombie.core.Core;
import zombie.debug.DebugLog;
import zombie.iso.IsoDirections;
import zombie.iso.sprite.IsoDirectionFrame;
import zombie.iso.sprite.IsoSprite;
import zombie.iso.sprite.IsoSpriteManager;
import zombie.network.GameServer;

public final class ErosionObjSprites {
    public static final int SECTION_BASE = 0;
    public static final int SECTION_SNOW = 1;
    public static final int SECTION_FLOWER = 2;
    public static final int SECTION_CHILD = 3;
    public static final int NUM_SECTIONS = 4;
    public String name;
    public int stages;
    public boolean hasSnow;
    public boolean hasFlower;
    public boolean hasChildSprite;
    public boolean noSeasonBase;
    public int cycleTime = 1;
    private ErosionObjSprites.Stage[] sprites;

    public ErosionObjSprites(int _stages, String _name, boolean _hasSnow, boolean _hasFlower, boolean _hasChildsprite) {
        this.name = _name;
        this.stages = _stages;
        this.hasSnow = _hasSnow;
        this.hasFlower = _hasFlower;
        this.hasChildSprite = _hasChildsprite;
        this.sprites = new ErosionObjSprites.Stage[_stages];

        for (int _int = 0; _int < _stages; _int++) {
            this.sprites[_int] = new ErosionObjSprites.Stage();
            this.sprites[_int].sections[0] = new ErosionObjSprites.Section();
            if (this.hasSnow) {
                this.sprites[_int].sections[1] = new ErosionObjSprites.Section();
            }

            if (this.hasFlower) {
                this.sprites[_int].sections[2] = new ErosionObjSprites.Section();
            }

            if (this.hasChildSprite) {
                this.sprites[_int].sections[3] = new ErosionObjSprites.Section();
            }
        }
    }

    private String getSprite(int int2, int int1, int int0) {
        return this.sprites[int2] != null && this.sprites[int2].sections[int1] != null && this.sprites[int2].sections[int1].seasons[int0] != null
            ? this.sprites[int2].sections[int1].seasons[int0].getNext()
            : null;
    }

    public String getBase(int _stage, int _season) {
        return this.getSprite(_stage, 0, _season);
    }

    public String getFlower(int _stage) {
        return this.hasFlower ? this.getSprite(_stage, 2, 0) : null;
    }

    public String getChildSprite(int _stage, int _season) {
        return this.hasChildSprite ? this.getSprite(_stage, 3, _season) : null;
    }

    private void setSprite(int int1, int int0, String string, int int2) {
        if (this.sprites[int1] != null && this.sprites[int1].sections[int0] != null) {
            this.sprites[int1].sections[int0].seasons[int2] = new ErosionObjSprites.Sprites(string);
        }
    }

    private void setSprite(int int1, int int0, ArrayList<String> arrayList, int int2) {
        assert !arrayList.isEmpty();

        if (this.sprites[int1] != null && this.sprites[int1].sections[int0] != null) {
            this.sprites[int1].sections[int0].seasons[int2] = new ErosionObjSprites.Sprites(arrayList);
        }
    }

    public void setBase(int _stage, String _sprite, int _season) {
        this.setSprite(_stage, 0, _sprite, _season);
    }

    public void setBase(int _stage, ArrayList<String> _sprites, int _season) {
        this.setSprite(_stage, 0, _sprites, _season);
    }

    public void setFlower(int _stage, String _sprite) {
        this.setSprite(_stage, 2, _sprite, 0);
    }

    public void setFlower(int _stage, ArrayList<String> _sprites) {
        this.setSprite(_stage, 2, _sprites, 0);
    }

    public void setChildSprite(int _stage, String _sprite, int _season) {
        this.setSprite(_stage, 3, _sprite, _season);
    }

    public void setChildSprite(int _stage, ArrayList<String> _sprites, int _season) {
        this.setSprite(_stage, 3, _sprites, _season);
    }

    private static class Section {
        public ErosionObjSprites.Sprites[] seasons = new ErosionObjSprites.Sprites[6];
    }

    private static final class Sprites {
        public final ArrayList<String> sprites = new ArrayList();
        private int index = -1;

        public Sprites(String string) {
            if (Core.bDebug || GameServer.bServer && GameServer.bDebug) {
                IsoSprite isoSprite = IsoSpriteManager.instance.getSprite(string);
                if (isoSprite.CurrentAnim.Frames.size() == 0
                    || !GameServer.bServer && ((IsoDirectionFrame)isoSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N) == null
                    || isoSprite.ID < 10000) {
                    DebugLog.log("EMPTY SPRITE " + string);
                }
            }

            this.sprites.add(string);
        }

        public Sprites(ArrayList<String> arrayList) {
            if (Core.bDebug || GameServer.bServer && GameServer.bDebug) {
                for (int _int = 0; _int < arrayList.size(); _int++) {
                    IsoSprite isoSprite = IsoSpriteManager.instance.getSprite((String)arrayList.get(_int));
                    if (isoSprite.CurrentAnim.Frames.size() == 0
                        || !GameServer.bServer && ((IsoDirectionFrame)isoSprite.CurrentAnim.Frames.get(0)).getTexture(IsoDirections.N) == null
                        || isoSprite.ID < 10000) {
                        DebugLog.log("EMPTY SPRITE " + (String)arrayList.get(_int));
                    }
                }
            }

            this.sprites.addAll(arrayList);
        }

        public String getNext() {
            if (++this.index >= this.sprites.size()) {
                this.index = 0;
            }

            return (String)this.sprites.get(this.index);
        }
    }

    private static class Stage {
        public ErosionObjSprites.Section[] sections = new ErosionObjSprites.Section[4];
    }
}
